import { ReqPage, ResPage } from '@/api/interface'
import { TBY } from '@/api/config/servicePort'
import http from '@/api'

export namespace UavInfo {
  /**查询参数 */
  export interface Query extends ReqPage {
    code?: string
    name?: string
    model?: string
  }

  /**列表内容 */
  export interface Record {
    id: number
    deviceId: string
    code: string
    name: string
    model: string
    flightCount: number
    flightDistance: number
    flightTime: number
    headName: string
    phone: string
    status: number
  }

  /**详情 */
  export interface Form {
    id: number
    deviceId: string
    code: string
    name: string
    model: string
    headName: string
    phone: string
  }

  export const StatusEnum = [
    { value: 0, label: '离线' },
    { value: 1, label: '在线' }
  ]
}

// 分页查询
export const pageUavInfo = (params: UavInfo.Query) => {
  return http.get<ResPage<UavInfo.Record>>(TBY + `/uav/page`, params)
}

// 列表查询
export const listUavInfo = (params: UavInfo.Query) => {
  return http.get<UavInfo.Record[]>(TBY + `/uav/list`, params)
}

// 详情信息
export const getUavInfoDetail = (id: number) => {
  return http.get<Partial<UavInfo.Form>>(TBY + `/uav/get`, { id }, { loading: false })
}

// 新增或修改
export const saveOrUpdateUavInfo = (params: Partial<UavInfo.Form>) => {
  return http.post(TBY + `/uav/save`, params)
}

// 删除
export const removeUavInfo = (id: number) => {
  return http.delete(TBY + `/uav/delete`, { id })
}

// 验证无人机编码是否存在
export const codeExist = (code: string, id?: number) => {
  return http.get<boolean>(TBY + '/uav/exist', { code, id }, { loading: false })
}

// 验证无人机设备id是否存在
export const deviceIdExist = (deviceId: string, id?: number) => {
  return http.get<boolean>(TBY + '/uav/device_exist', { deviceId, id }, { loading: false })
}
